<template>
    <!--    <div>载体</div>-->
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
            <el-form-item label="任务编号" prop="assignmentNumber">
                <el-input v-model="queryParams.assignmentNumber" type="number" placeholder="请输入任务编号" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="任务名称" prop="assignmentName">
                <el-input v-model="queryParams.assignmentName" placeholder="请输入任务名称" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8" ref="refbut">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd">添加</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table ref="table" v-loading="loading" :data="dataList" :height="tableHeight"
            @selection-change="handleSelectionChange" border stripe>
            <el-table-column type="selection" width="50" align="center" fixed="left" />
            <el-table-column label="序号" sortable align="center" type="index" prop="id" />
            <el-table-column label="任务编号" prop="assignmentNumber" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="任务名称" prop="assignmentName" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="执行方式" prop="executionMode" align="center" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    {{ scope.row.executionMode == '0' ? "手动" : "自动" }}
                </template>
            </el-table-column>
            <el-table-column label="备份方式" prop="backupMethod" align="center">
                <template slot-scope="scope">
                    {{ scope.row.backupMethod == '0' ? "增量" : "全量" }}
                </template>
            </el-table-column>
            <el-table-column label="执行表达式" prop="executeExpression" align="center"></el-table-column>
            <el-table-column label="原地址" prop="originalAddress" align="center"></el-table-column>
            <el-table-column label="备份地址" prop="backupAddress" align="center"></el-table-column>
            <el-table-column label="启动状态" align="center" >
                <template slot-scope="scope" v-if="scope.row.executionMode == '1'">
                    <el-switch v-model="scope.row.startupStatus" active-value="1" inactive-value="0"
                        @change="handleStatusChange(scope.row)"></el-switch>
                </template>
            </el-table-column>
            <el-table-column label="创建时间" prop="createTime" align="center"></el-table-column>
            <el-table-column label="操作" align="center" width="300px">
                <template slot-scope="scope">
                    <el-button plain type="success" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
                    <el-button plain type="warning" size="mini" @click="handleZuPanGz(scope.row)">备份</el-button>
                    <el-button plain type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />



        <deitfileBackup v-if="deitOpen" :deitOpen="deitOpen" :Id="Id" @closeDelDialog="closeDelDialog"
            @addsubmitForm="addsubmitForm"></deitfileBackup>
    </div>
</template>

<script>
import estimateTableHeight from "@/mixins/estimateTableHeight";

import { filebackupList, filebackupdelete,updateState,backup} from "@/api/cqbc/backupRestore/filebackup.js"
import deitfileBackup from "@/views/cqbc/backupRestore/filebackup/deitfileBackup.vue"
export default {
    mixins: [estimateTableHeight], // 混入方法
    archive_Dicts: ['CARRIER_TYPE'],
    components: {
        deitfileBackup
    },
    data() {
        return {
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            dataList: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                assignmentNumber: undefined,
                assignmentName: undefined
            },
            deitOpen: false,
            Id: undefined,  //判断新增修改
        }
    },
    created() {
        this.getList()
    },
    methods: {
        closeDelDialog() {
            this.deitOpen = false;
        },
        getList() {
            filebackupList(this.queryParams).then(response => {
                this.dataList = response.rows
                this.total = response.total
                this.loading = false
            })
        },
        // 状态修改
        handleStatusChange(row) {
            console.log(row)
            let text = row.startupStatus === "1" ? "启用" : "停用";
            this.$modal.confirm('确认要"' + text + '""' + row.assignmentName + '"的任务名称吗？').then(function () {
                return updateState({id:row.id,startupStatus:row.startupStatus});
            }).then(() => {
                this.$modal.msgSuccess(text + "成功");
            }).catch(function () {
                row.startupStatus = row.startupStatus === "1" ? "1" : "0";
            });
        },
        handleQuery() {
            this.getList();
        },
        resetQuery() {
            this.queryParams = {
                pageNum: 1,
                pageSize: 10,
                assignmentNumber: undefined,
                assignmentName: undefined
            },
                this.getList();
        },
        table_index(index) {
            return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },

        // 新增
        handleAdd() {
            this.Id = undefined;
            this.deitOpen = true
        },
        // 修改
        handleUpdate(row) {
            this.Id = row.id;
            this.deitOpen = true
        },
        addsubmitForm() {
            this.deitOpen = false;
            this.getList()
        },
        cancelForm() {
            this.open = false
        },
        // 删除
        handleDelete(row) {
            const id = row.id || this.ids
            this.$modal.confirm('是否确认删除任务名称为"' + row.assignmentName + '"的数据项？').then(function () { }).then(() => {
                filebackupdelete(id).then(res => {
                    if (res.code == "200") {
                        this.$modal.msgSuccess("删除成功");
                        this.getList();
                    }
                })
            }).catch(() => { });
        },


        handleZuPanGz(row) {


            const id = row.id || this.ids
            this.$modal.confirm('是否确认备份任务名称为"' + row.assignmentName + '"的数据项？').then(function () { }).then(() => {
                backup({id:id}).then(res => {
                    if (res.code == "200") {
                        this.$modal.msgSuccess("备份成功");
                        this.getList();
                    }
                })
            }).catch(() => { });
        },
        closeZPGZDialog() {
            this.gzOpen = false;
        },
    }
}
</script>

<style></style>
